<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="99px" style="padding-right: 5px;">
        <el-row>
          <el-col :span="8">
            <el-form-item label="任务名称:" prop="title" style="width: 100%;">
                <el-input
                  v-model="queryParams.title"
                  placeholder="请输入任务名称"
                  clearable
                  prefix-icon="Search"
                  style="margin-bottom: 20px"
               />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="任务阶段" prop="stage" style="width: 100%;">
              <el-select v-model="queryParams.stage" placeholder="请选择任务阶段" clearable>
                <el-option
                  v-for="dict in stageList1"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="时间" prop="dateRange" style="width: 100%;">
              <el-date-picker
                  v-model="dateRange"
                  value-format="YYYY-MM-DD"
                  type="daterange"
                  range-separator="-"
                  start-placeholder="时间起"
                  end-placeholder="时间止"
                  style="width: 430px"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
  
      <el-row :gutter="10" class="mb8" style="margin: 15px 0px;">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['partybuilding:ReleaseTask:add']"
          >新建</el-button>
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" @handleQuery="handleQuery" @resetQuery="resetQuery"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="releaseTaskList" @selection-change="handleSelectionChange">
        <el-table-column label="序号" type="index" width="90"/>
        <el-table-column label="任务名称" align="left" prop="title" min-width="200"/>
        <el-table-column label="任务内容" align="left" prop="content" min-width="200" show-overflow-tooltip="true"/>
        <el-table-column label="任务阶段" align="left" prop="stage" width="150">
            <template #default="scope">
                <dict-tag :options="stageList" :value="scope.row.stage" />
            </template>
        </el-table-column>
        <el-table-column label="发起人" align="left" prop="originator" width="150"/>
        <el-table-column label="揭榜人" align="left" prop="implementer" width="150"/>
        <el-table-column label="创建时间" align="left" prop="createTime" width="200">
            <template #default="scope">
               <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
        </el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="100">
          <template #default="scope">
            <el-button link type="danger" @click="handleView(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
      <!-- 申请或修改工作任务对话框 -->
      <add-put-leader ref="putLeaderRef" :parentMethod="parentMethod"></add-put-leader>

      <!-- 查看工作任务对话框 -->
      <view-put-leader ref="viewPutLeaderRef" :parentMethod="parentMethod"></view-put-leader>
    </div>
  </template>
  
  <script setup name="searchbill">
  import { listReleaseTask, getReleaseTask, delReleaseTask, submitReleaseTask } from "@/api/putleader/putleader";
  import AddPutLeader from './component/AddPutLeader.vue';
  import ViewPutLeader from './component/ViewPutLeader.vue';
  const { proxy } = getCurrentInstance();
  const releaseTaskList = ref([]);
  const loading = ref(true);
  const showSearch = ref(true);
  const ids = ref([]);
  const single = ref(true);
  const multiple = ref(true);
  const total = ref(0);
  const dateRange = ref([]);
  //阶段：0草稿，1申请中(寻榜)、20审批通过(定榜)、21审批驳回、30发榜、40揭榜、50攻榜、60完成、61评榜、62奖榜、63用榜
  const stageList = ref([
    {label: '草稿', value: '0'}, 
    {label: '寻榜', value: '1'}, 
    {label: '定榜', value: '20'},
    {label: '审批驳回', value: '21'}, 
    {label: '发榜', value: '30'}, 
    {label: '揭榜', value: '40'},
    {label: '攻榜', value: '50'}, 
    {label: '挂帅成功', value: '60'}, 
    {label: '评榜', value: '61'},
    {label: '奖榜', value: '62'}, 
    {label: '用榜', value: '63'}]);
  const stageList1 = ref([
    {label: '草稿', value: '0'}, 
    {label: '寻榜', value: '1'}, 
    {label: '定榜', value: '20'},
    {label: '审批驳回', value: '21'}, 
    {label: '发榜', value: '30'}, 
    {label: '揭榜', value: '40'},
    {label: '攻榜', value: '50'}, 
    {label: '挂帅成功', value: '60'}]);
  
  const data = reactive({
    queryParams: {
      pageNum: 1,
      pageSize: 10,
      title: null,
      begin: null,
      createTime2: null,
      stage: null
    }
  });
  
  const { queryParams } = toRefs(data);

  /** 查询工作任务列表 */
  function getList() {
    loading.value = true;
    if (dateRange.value.length > 0) {
      if (dateRange.value[0] != null && dateRange.value[0] != null) {
        queryParams.value.createTime = dateRange.value[0]+' 00:00:00';
      }
      if (dateRange.value[1] != null && dateRange.value[1] != null){
        queryParams.value.createTime2 = dateRange.value[1]+' 23:59:59';
      }
    }
    listReleaseTask(queryParams.value).then(response => {
      releaseTaskList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    });
  }

  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
  }
  
  /** 重置按钮操作 */
  function resetQuery() {
    dateRange.value = [];
    queryParams.value.createTime = null;
    queryParams.value.createTime2 = null;
    proxy.resetForm("queryRef");
    handleQuery();
  }
  
  // 多选框选中数据
  function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.id);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
  }
  
  /** 新增按钮操作 */
  function handleAdd() {
    proxy.$refs["putLeaderRef"].show(null, "录入工作任务", false);
  }
  
  /** 查看 */
  function handleView(row) {
    getReleaseTask(row.id).then(response => {
        proxy.$refs["viewPutLeaderRef"].show(response.data, "查看工作任务", true);
    });
  }

  /** 编辑 */
  function handleEdit(row) {
    getReleaseTask(row.id).then(response => {
        proxy.$refs["putLeaderRef"].show(response.data, "编辑工作任务", false);
    });
  }

  /** 提交按钮操作 */
  function handleSubmit(row) {
    proxy.$modal.confirm('是否确认提交申请？').then(function() {
      return submitReleaseTask({id: row.id});
    }).then(() => {
      getList();
      proxy.$modal.msgSuccess("提交成功");
    }).catch(() => {});
  }

  /** 删除按钮操作 */
  function handleDelete(row) {
    const _ids = row.id || ids.value;
    proxy.$modal.confirm('是否确认删除任务名称为"' + row.title + '"的数据项？').then(function() {
      return delReleaseTask(_ids);
    }).then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    }).catch(() => {});
  }

  //新增或修改回调函数
  function parentMethod(data) {
    getList();
  }

  getList();
  </script>
  
  <style lang="scss" scoped>
  .el-dialog > .el-dialog__body {
    border-top: 1px solid red;
    border-bottom: 1px solid #e9e9e9;
  }
  .spanUserTitle {
    height: 22px;
    background-color: rgb(255, 255, 255);
    color: rgb(51, 51, 51);
    font-size: 16px;
    text-align: left;
    font-family: PingFangSC-Regular;
  }
  .itemTogetherTitle {
      font-size: 14px;
      text-align: left;
      font-family: PingFangSC-Regular;
      color: rgb(153, 153, 153) !important;
      padding: 19px 59px;
  }
  .dialog-top-line {
    width: 100%;
    height: 1px;
    background-color: #ccc;
    position: absolute;
    left: 0px;
    top: 49px;
  }
  .dialog-bottom-line {
    width: 100%;
    height: 1px;
    background-color: #ccc;
    position: absolute;
    left: 0px;
    bottom: 65px;
  }
  .formPeopleStyle {
    position: relative;
  }
  .formPeopleStyle::before {
    content: "*";
    color: #F56C6C;
    position: absolute;
    left: 4px;
    top: 9px;
  }
  .formPeopleStyle1 {
    position: relative;
  }
  .formPeopleStyle1::before {
    content: "*";
    color: #F56C6C;
    position: absolute;
    left: 30px;
    top: 9px;
  }
  .personDiv {
    margin: 5px;
  }
  .singlePersonDiv {
    position: relative;
    display: block;
    width: 64px;
    height: 66px;
    float: left;
    margin-top: 10px;
    margin-bottom: 15px;
    margin-right: 10px;
    cursor: pointer;
    .closeDiv {
        position: absolute;
        top: -11px;
        right: 7px;
        font-size: 16px;
        cursor: pointer;
     }
    .circleAndText {
        width: 44px;
        height: 44px;
        line-height: 44px;
        text-align: center;
        border-radius: 50%;
        border: 1px solid #ffe3e3;
        color: #333;
        font-size: 14px;
        background-color: rgba(255, 77, 79, .06);
    }
    .bottomText {
        font-size: 14px;
        color: #595959;
        margin-top: -1px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
  }
  </style>